package com.juzipi.demo.demeter;

import java.util.ArrayList;
import java.util.List;

public class Demeter1 {

    public static void main(String[] args) {
        //创建了一个 SchoolManager 对象
        SchoolManager schoolManager = new SchoolManager();
        //输出了学院的员工id和学校总部的员工信息
        schoolManager.printAllEmployee(new CollegeManager());


    }

}

//学校总部员工
class Employee {
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

//学院的员工
class CollegeEmployee {
    private String id;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

//管理学院员工的管理类
class CollegeManager {
    //返回学院的所有员工
    public List<CollegeEmployee> getAllEmployee(){
        ArrayList<CollegeEmployee> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            CollegeEmployee collegeEmployee = new CollegeEmployee();
            collegeEmployee.setId("学院员工id"+i);
            list.add(collegeEmployee);
        }
        return list;
    }

}

//管理学校总部id
//分析 SchoolManager 类有哪些直接朋友类 Employee,CollegeManager
//CollegeEmployee 不是直接朋友而是一个陌生类，违背了迪米特原则
class SchoolManager {
    public List<Employee> getAllEmployee(){
        ArrayList<Employee> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Employee employee = new Employee();
            employee.setId("学校总部id"+i);
            list.add(employee);
        }
        return list;
    }

    //该方法完成输出学校总部和学院员工信息
    void printAllEmployee(CollegeManager collegeManager){
        /*分析问题
        1.这里的 CollegeEmployee 不是 SchoolManager 的直接朋友
        2.CollegeEmployee 是以局部变量的方式出现在 SchoolManager
        3.违反了 迪米特法则
         */
        //获取到学院员工
        List<CollegeEmployee> allEmployee = collegeManager.getAllEmployee();
        System.out.println("----------------分公司员工----------------");
        for (CollegeEmployee co : allEmployee){
            System.out.println(co.getId());
        }

        //获取到学校总部员工
        List<Employee> employee = this.getAllEmployee();
        System.out.println("----------------学校总部员工----------------");
        for (Employee eo : employee){
            System.out.println(eo.getId());
        }

    }
}